package ar.com.guess.image.entities;

import java.io.Serializable;
import java.util.StringTokenizer;

import ar.com.guess.image.enums.Constant;

/**
 * Imagen que contiene el nombre del resource (archivo) con el valor que hay que adivinar.
 * 
 * @author Gatex
 *
 */
public class Image implements Serializable{
	
	private static final long serialVersionUID = 3753497078941656138L;

	private int identifierResource;
	
	private String valueToGuess;
	
	private Boolean wasGuess;
	
	public Image(int identifierResource, String valueToGuess) {
		super();
		this.identifierResource = identifierResource;
		this.valueToGuess = valueToGuess;
		this.wasGuess = false;
	}

	public String getValueToGuess() {
		return valueToGuess;
	}
	
	public void setValueToGuess(String valueToGuess) {
		this.valueToGuess = valueToGuess;
	}
	
	public void setIdentifierResource(int identifierResource) {
		this.identifierResource = identifierResource;
	}
	
	public int getIdentifierResource() {
		return identifierResource;
	}
	
	public int getLengthWithOutSpace(){
		StringTokenizer tokenizer = new StringTokenizer(this.valueToGuess,Constant.SPACE.getValue());
		int length = 0;
		while (tokenizer.hasMoreTokens()){
			length += tokenizer.nextToken().length();
		}
		return length;
	}
	
	public void setWasGuess(Boolean wasGuess) {
		this.wasGuess = wasGuess;
	}
	
	public Boolean wasGuess(){
		return this.wasGuess;
	}
	
	@Override
	public boolean equals(Object o) {
		if (o == null){
			return false;
		}
		if (!(o instanceof Image)){
			return false;
		}
		Image other = (Image) o;
		if (other.valueToGuess.equals(this.valueToGuess) && other.identifierResource == this.identifierResource){
			return true;
		}
		return false;
	}
	
}
